﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;
using SimpleExpressionEvaluator.Evaluation;

namespace SimpleExpressionEvaluator.Tests.Evaluation
{
    [TestFixture]
    public class QualifiedNameResolutionServiceTestFixture
    {
        [Test]
        public void Can_Resolve_Qualified_Name()
        {
            var res = new QualifiedNameResolutionService();
            object val = res.ResolveQualifiedName(DateTime.Now, new[] {"date","hour"});
            Assert.That(val, Is.EqualTo(DateTime.Now.Date.Hour));
        }

        [Test]
        public void Can_Extrapolate_Type_Name_From_Static_Property_Path()
        {
            var res = new QualifiedNameResolutionService();
            object val = res.ResolveQualifiedName(null, new[] {"System.DateTime", "now", "date", "hour"});
            Assert.That(val, Is.EqualTo(DateTime.Now.Date.Hour));
        }

        [Test]
        public void Will_Use_Custom_Resolver()
        {
            var context = DateTime.Now;
            var name = new[]{"aMadeUpProperty"};

            var custom = MockRepository.GenerateStub<IQualifiedNameResolutionService>();
            custom.Stub(x => x.ResolveQualifiedName(context, name)).Return("aMadeUpResponse");

            var res = new QualifiedNameResolutionService();
            res.AddResolutionService(custom);

            object val = res.ResolveQualifiedName(context, name);

            Assert.That(val, Is.EqualTo("aMadeUpResponse"));
            custom.AssertWasCalled(x => x.ResolveQualifiedName(context, name));

        }
    }
}
